#include <linux/module.h>

#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/tty.h>
#include <linux/kmod.h>
#include <linux/gfp.h>
#include "led_opr.h"
#include "led_resource.h"

static struct led_resource *led_resource;

static int board_demo_init (int which) 
{
    // printk("%s %s %s %d\n", __FILE__, __FUNCTION__, __LINE__, which);

    if (!led_resource)
    {
        led_resource = get_led_resource();
    }

    printk("init gpio: group %d - pin %d \n", GROUP(led_resource->pin), PIN(led_resource->pin));

    switch (led_resource->pin)
    {
    case 0:
        printk("init pin of group 0 ...\n");
        break;
    case 1:
        printk("init pin of group 1 ...\n");
        break;
    default:
        break;
    }
    

    return 0;
}

static int board_demo_ctl (int which, char status) 
{
    printk("set led %s: group %d, pin %d\n", status ? "on" : "off", GROUP(led_resource->pin), PIN(led_resource->pin));
    switch (GROUP(led_resource->pin))
    {
    case 0:
    {
        printk("set pin of group 0 ...\n");
        break;
    }
    case 1:
    {
        printk("set pin of group 1 ...\n");
        break;
    }
    default:
        break;
    }
    return 0;
}

static struct led_operations board_demo_led_opr = {
    .init = board_demo_init,
    .ctl = board_demo_ctl,
};

struct led_operations *get_board_led_opr(void)
{
    return &board_demo_led_opr;
};

